import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common.dart';

class Index extends StatefulWidget {
  Index({super.key});
  @override
  State<Index> createState() => _QGRulePageState();
}

class _QGRulePageState extends State<Index> {
  var items = [
    {'img': "hecheng", "txt": "合成"},
    {'img': "fenjie", "txt": "分解"},
    {'img': "zhihuan", "txt": "置换"},
    {'img': "shengji", "txt": "升级"},
    {'img': "yaoqing", "txt": "邀请"},
    {'img': "choujiang", "txt": "抽奖"},
    {'img': "paihang", "txt": "排行榜"},
  ];

  var serviceList = [
    {'img': "shoucang", "txt": "我的收藏"},
    {'img': "dingdan", "txt": "藏品订单"},
    {'img': "dingwei", "txt": "收货地址"},
    {'img': "rili", "txt": "发售日历"},
  ];
  var assetsList = [
    {'img': "qianbao", "txt": "钱包"},
    {'img': "jifen", "txt": "兑换明细"},
    {'img': "kongtou", "txt": "空投"},
  ];
  var user = {};
  @override
  void initState() {
    super.initState();
    user = myget('user');
  }

  @override
  Widget build(BuildContext context) {
    final totalw = (MediaQuery.of(context).size.width - 30) / 4;

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0XFFFFFFFF),
        centerTitle: true,
        leading: buildBackButton(context),
      ),
      body: ListView(
        padding: EdgeInsets.symmetric(horizontal: 15),
        children: [
          Row(
            children: [
              GestureDetector(
                onTap: () {
                  // toNamed('/user/personal/index');
                },
                child: Stack(
                  children: [
                    wImage(
                      url: user['headimg'],
                      width: 60,
                      height: 60,
                      borderRadius: 60,
                    ),
                    // Positioned(
                    //   left: 3,
                    //   right: 3,
                    //   bottom: 0,
                    //   child: Container(
                    //     padding: EdgeInsets.symmetric(
                    //       horizontal: 2,
                    //       vertical: 3,
                    //     ),
                    //     decoration: BoxDecoration(
                    //       color: Color(0XFF6828FF),
                    //       borderRadius: BorderRadius.circular(5),
                    //     ),
                    //     child: wText(text: '个人空间', color: 'FFFFFF'),
                    //   ),
                    // ),
                  ],
                ),
              ),
              SizedBox(width: 10),
              GestureDetector(
                onTap: () {
                  // toNamed('/user/personal/index');
                },
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        wText(text: user['name'], size: 16),
                        // wImage(url: 'lanv', width: 16),
                      ],
                    ),

                    // wText(text: 'UID:${user['uuid']}', color: '878b95'),
                    if (user['metaAddress'].isNotEmpty)
                      wText(
                        text:
                            '区块链地址:${user['metaAddress'].substring(0, 5)}....${user['metaAddress'].substring(user['metaAddress'].length - 4)}',
                        color: '0F172B',
                      ),
                    if (user['metaAddress'].isEmpty)
                      wText(text: '区块链地址:请先实名', color: '0F172B'),
                  ],
                ),
              ),
              Expanded(child: SizedBox()),
              GestureDetector(
                onTap: () {
                  toNamed('/user/setting').then((res) {
                    user = myget('user');
                    setState(() {});
                  });
                },
                child: wImage(url: 'shezhi', width: 24),
              ),
            ],
          ),
          Divider(height: 50, color: Color(0XFFF3F3F4)),
          wText(text: '活动中心', bold: true, size: 18),
          SizedBox(height: 20),
          Wrap(
            runSpacing: 20,
            children: List.generate(items.length, (index) {
              return GestureDetector(
                onTap: () {
                  print(items[index]['txt']);
                  if (items[index]['txt'] == '合成') {
                    toNamed('/web_tabs/activity/synthesis?type=1');
                  } else if (items[index]['txt'] == '抽奖') {
                    toNamed('/web_tabs/lottery/lottery_draw');
                  } else if (items[index]['txt'] == '升级') {
                    toNamed('/web_tabs/activity/synthesis?type=1&jing=2');
                  } else if (items[index]['txt'] == '分解') {
                    toNamed('/web_tabs/activity/synthesis?type=2');
                  } else if (items[index]['txt'] == '置换') {
                    toNamed('/web_tabs/activity/synthesis?type=3');
                  } else if (items[index]['txt'] == '排行榜') {
                    showqidai();
                  } else if (items[index]['txt'] == '邀请') {
                    toNamed('/web_tabs/invitation');
                  }
                },
                child: Container(
                  width: totalw,
                  child: Column(
                    children: [
                      wImage(url: '${items[index]['img']}', width: 34),
                      wText(text: '${items[index]['txt']}'),
                    ],
                  ),
                ),
              );
            }),
          ),
          Divider(height: 50, color: Color(0XFFF3F3F4)),
          wText(text: '我的服务', bold: true, size: 18),
          SizedBox(height: 20),
          Wrap(
            runSpacing: 20,
            children: List.generate(serviceList.length, (index) {
              return GestureDetector(
                onTap: () {
                  if (serviceList[index]['txt'] == '藏品订单') {
                    toNamed('/user/order_list');
                  } else if (serviceList[index]['txt'] == '发售日历') {
                    toNamed('/home/release_calendar');
                  } else if (serviceList[index]['txt'] == '收货地址') {
                    toNamed('/web_tabs/shopping/mall_address');
                  } else if (serviceList[index]['txt'] == '我的收藏') {
                    toNamed('/user/collect');
                  }
                },
                child: Container(
                  width: totalw,
                  child: Column(
                    children: [
                      wImage(url: '${serviceList[index]['img']}', width: 34),
                      wText(text: '${serviceList[index]['txt']}'),
                    ],
                  ),
                ),
              );
            }),
          ),

          Divider(height: 50, color: Color(0XFFF3F3F4)),
          wText(text: '我的资产', bold: true, size: 18),
          SizedBox(height: 20),
          Wrap(
            runSpacing: 20,
            children: List.generate(assetsList.length, (index) {
              return GestureDetector(
                onTap: () {
                  if (assetsList[index]['txt'] == '钱包') {
                    toNamed('/user/mall_wallet');
                  } else if (assetsList[index]['txt'] == '兑换明细') {
                    toNamed('/user/mall_integral');
                  } else if (assetsList[index]['txt'] == '空投') {
                    showqidai();
                  }
                },
                child: Container(
                  width: totalw,
                  child: Column(
                    children: [
                      wImage(url: '${assetsList[index]['img']}', width: 34),
                      wText(text: '${assetsList[index]['txt']}'),
                    ],
                  ),
                ),
              );
            }),
          ),
          Divider(height: 50, color: Color(0XFFF3F3F4)),
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              toNamed('/agreement?type=2');
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                wText(text: '隐私政策', size: 16),
                wImage(url: 'hbottom', width: 16),
              ],
            ),
          ),
          SizedBox(height: 25),
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              toNamed('/agreement?type=1');
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                wText(text: '服务条款', size: 16),
                wImage(url: 'hbottom', width: 16),
              ],
            ),
          ),
          SizedBox(height: 25),

          // Row(
          //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //   children: [
          //     wText(text: '联系我们', size: 16),
          //     wImage(url: 'hbottom', width: 16),
          //   ],
          // ),
          // SizedBox(height: 25),
        ],
      ),
    );
  }
}
